package com.jbit.hxy.controller;

import com.jbit.hxy.common.Result;
import com.jbit.hxy.model.dto.WxAddressFromDTO;
import com.jbit.hxy.service.adress.WxAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/address")
@RequiredArgsConstructor
@Tag(name = "地址模块")
public class WXAddressController {
    private final WxAddressService wxAddressService;
    @GetMapping("/getAddress")
    @Operation(summary = "获取地址",description = "获取地址")
    public Result getAddress(@RequestParam("userId") Integer userId) {
        return wxAddressService.getAddress(userId);
    }
    @PostMapping("/addAddress")
    @Operation(summary = "添加地址",description = "添加地址")
    public Result addAddress(@RequestBody WxAddressFromDTO wxAddressFromDTO) {
        return wxAddressService.addAddress(wxAddressFromDTO);
    }
    @PostMapping("/updateAddress")
    @Operation(summary = "更新地址",description = "更新地址")
    public Result updateAddress(@RequestBody WxAddressFromDTO wxAddressFromDTO) {
        return wxAddressService.updateAddress(wxAddressFromDTO);
    }
    @GetMapping("/deleteAddress")
    @Operation(summary = "删除地址",description = "删除地址")
    public Result deleteAddress(@RequestParam("id") Integer id) {
        return wxAddressService.deleteAddress(id);
    }

    @GetMapping("/getAddressByUserId")
    @Operation(summary = "根据用户id获取默认地址",description = "根据用户id获取默认地址")
    public Result getAddressByUserId(@RequestParam("userId") Integer userId) {
        return wxAddressService.getAddressByUserId(userId);
    }


}
